Skip to content

Conversation

@tamara-schmitz
Copy link

Up until now, the stop bits value was hard coded to be 2 if the parity mode was set to none or 1 if the parity mode was set to even or odd.

So a setting of "115200E1" would result in a stop bit value of 1. But "115200E2" would result also in a stop bit value of 1. And "115200N1" would result in a stop bit value of 2.

This is not a restriction of libmodbus. The library supports all these modes just fine. In fact they are using 115200N1 in the documentation for modbus_new_rtu().

Rather this is a bug in the string parsing that libmodbuspp introduces in its constructor.
libmodbus has no string parsing in modbus_new_rtu() and takes in the arguments as parameters directly.

Fixes: b0f3dc4

@tamara-schmitz tamara-schmitz force-pushed the fix-parsing branch 3 times, most recently from b76b5ab to 314baac Compare December 13, 2024 08:26
@tamara-schmitz
Copy link
Author

I have refreshed the patch to throw an exception when the given parameters cannot be parsed or are invalid. This is a lot better than just silently "fixing" them.

Also to compile this I added a patch to fix a missing include, mentioned in #24 and in PR #22.

Throw exceptions on error instead of silently changing values.
Check settings string for given stop bit value.

Up until now, the stop bits value was hard coded to be 2 if the parity
mode was set to none or 1 if the parity mode was set to even or odd.

So a setting of "115200E1" would result in a stop bit value of 1.
But "115200E2" would result also in a stop bit value of 1.
And "115200N1" would result in a stop bit value of 2.

This is not a restriction of libmodbus. The library supports all these
modes just fine. In fact they are using 115200N1 in the documentation
for modbus_new_rtu().

Rather this is a bug in the string parsing that libmodbuspp introduces
in its constructor.
libmodbus has no string parsing in modbus_new_rtu() and takes in the
arguments as parameters directly.

Fixes: b0f3dc4
@epsilonrt
Copy link
Owner

I had not planned the integration of ASCII in libmodbus, even if its modular design allows it.
The format of a character in RTU MUST be 11 bits long, it is explained in the specifications.
So if a parity is used, the number of stop bits is 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants